package pool;

import java.util.concurrent.*;

/*
自定义线程池
 */
public class ThreadPoolDemo4 {

  public static void main(String[] args) {

    ExecutorService executorService = new ThreadPoolExecutor(
            2,
            5,
            2l,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(3),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy()
            );
    //    自定义线程
    try{
      for (int i = 0; i < 10; i++) {
        executorService.execute(()->{
          System.out.println(Thread.currentThread().getName() + "办理业务");
        });
      }
    }catch (Exception e){
      e.printStackTrace();
    }finally {
      executorService.shutdown();
    }
  }
}
